<template>
  <div>
    <div style="display:flex;flex-direction:row-reverse;margin-top:10px">
      <el-button :disabled="submitLoading" size="mini" type="primary" @click="submitForm(0)">保存</el-button>
      <el-button style="margin-right:20px" :disabled="submitLoading" size="mini" type="primary" @click="submitForm(1)">提交</el-button>
    </div>
    <div v-loading="dataLoading">
      <base-info :base-info="detailData" />
      <!-- <drawing-info :base-info="detailData" /> -->
      <distribute :base-info="detailData" />
      <config-info :base-info="detailData" />
      <studio-confirm :base-info="detailData" />
      <config-info :config-type="1" :base-info="detailData" />
    </div>
    <div style="margin-top:20px" class="qup-title-box"><span class="border" /><span>转化分配</span></div>

    <el-form
      ref="refForm"
      :rules="formRules"
      :model="formData"
      size="mini"
      label-width="150px"
    >

      <el-row>
        <el-col :span="8">
          <el-form-item :rules="[{ required: true, message: '请选择图纸转化专员', trigger: 'change' }]" label="图纸转化专员:" prop="drawingChanger">
            <input-with-dialog
              v-model="people"
              :props="{label:'userName',value:'account'}"
              multiple
              :config="{
                title:'图纸转化专员',
                width:'600px',
                interfacePath:`/slm-admin/api/v1/user/listUsers`,
                method:'post',
                filtersRaw:[],
                paramsRaw:{},
                setting:[
                  {prop:'account',title:'编码'},
                  {prop:'userName',title:'名称'}
                ]
              }"
              @change="handleChangePeople"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="转化分配时间:" prop="drawingChangeTime">
            <el-input v-model="formData.drawingChangeTime" disabled />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import BackPageMixin from '@/mixins/backPage'
import { queryDetail, submitTransDistribute } from '@/api/autoDesignTask'
import baseInfo from './component/BaseInfo.vue'
import drawingInfo from './component/DrawingInfo.vue'
import distribute from './component/distributeInfo.vue'
import configInfo from './component/ConfigInfo.vue'
import studioConfirm from './component/StudioConfirm'

export default {
  name: 'TransDistribute',
  components: { baseInfo, drawingInfo, distribute, configInfo, studioConfirm },
  mixins: [BackPageMixin],
  props: {
  },
  data() {
    return {
      id: '',
      detailData: {},
      people: [],
      submitLoading: false,
      dataLoading: false,
      formData: {
        id: '',
        drawingChangeTime: '',
        drawingChanger: '',
        drawingChangerCode: ''
      },
      formRules: { }
    }
  },
  watch: {
  },
  async  created() {
    this.id = this.$route.query.id
    if (this.id) {
      this.dataLoading = true
      queryDetail(this.id).then(res => {
        if (res.success) {
          this.detailData = res.data
          const { drawingChangeTime, drawingChanger, drawingChangerCode, id } = res.data
          this.formData = { drawingChangeTime, drawingChanger, drawingChangerCode, id }
          this.people = [{ value: this.formData.drawingChangerCode, label: this.formData.drawingChanger }]
          this.dataLoading = false
        }
      })
    }
    this.dataLoading = false
  },
  mounted() {
  },
  methods: {
    handleChangePeople(data) {
      if (data && data.length > 0) {
        const list1 = data.map(v => v.userName)
        const list2 = data.map(v => v.account)
        this.$set(this.formData, 'drawingChanger', list1.join(','))
        this.$set(this.formData, 'drawingChangerCode', list2.join(','))
      } else {
        this.$set(this.formData, 'drawingChanger', '')
        this.$set(this.formData, 'drawingChangerCode', '')
      }
    },
    goBack() {
      this.$store.dispatch('views/goBack')
    },
    submitForm(type) {
      if (this.submitLoading) return
      this.$refs['refForm'].validate((valid) => {
        if (valid) {
          this.submitLoading = true
          submitTransDistribute(this.formData, type).then(res => {
            if (res.success) {
              this.submitLoading = false
              this.$message.success('操作成功')
              this.goBack()
            }
          }).catch(() => {
            this.submitLoading = false
          })
        }
      })
    }

  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-breadcrumb__inner{
    color: $qup-color-primary;
  }
</style>
